package cn.ekuma.data.ui.android;


import java.util.ArrayList;
import java.util.List;

import com.openbravo.data.basic.BasicException;

import android.app.ProgressDialog;
import android.os.Bundle;
import cn.ekuma.data.dao.I_DataLogic;
import cn.ekuma.data.dao.I_ParentNode;
import cn.ekuma.data.dao.bean.I_BaseBean;
import cn.ekuma.data.dao.bean.I_ViewBean;

public abstract class AbstractListChildFinderActivate<T extends I_ViewBean,P extends I_BaseBean<String>> extends AbstractListFinderActivate<T>{
	 
	 public AbstractListChildFinderActivate(I_DataLogic dataLogic) {
		super(dataLogic);
		// TODO Auto-generated constructor stub
	}

	public static final String PARENT_BEAN="parent_bean";

	 protected P parent;
	 
		@Override
	protected void onCreate(Bundle savedInstanceState) {
			Bundle mBundle=getIntent().getExtras();
			parent=(P) mBundle.getSerializable(PARENT_BEAN);
			super.onCreate(savedInstanceState);
	}
	
		@Override
		protected void onResume() {
			super.onResume();
			loadData();
		}
		
		protected void loadData() {
			final ProgressDialog dialog = ProgressDialog.show(this, "", 
			        "查旬中，请稍等 …", true, true);
			new Thread(){
				@Override
				public void run(){
					try {
						List<T> lists=dataLogic.listWithParentClassAndKey(getFindClass().getName(), getParentClass().getName(), parent.getKey());
						if(lists==null)
							lists=new ArrayList();
					    mHandler.obtainMessage(MSG_SUCCESS, lists).sendToTarget();			
					} catch (BasicException e) {
						mHandler.obtainMessage(MSG_FAILURE).sendToTarget();//获取图片失败   
					}
					dialog.dismiss(); 
				}
				}.start();		
		}	
		
	public abstract Class getFindClass();	
		
	public abstract Class getParentClass();
}
